﻿using System;

namespace Program20
{
    class Program
    {
        static void Main(string[] args)
        {
            //1.用方法来实现：有一个字符串数组：{ "马龙", "迈克尔乔丹", "雷吉米勒", "蒂姆邓肯", "科比布莱恩特" },请输出最长的字符串。
            Console.WriteLine(LongString(new string[] { "马龙", "迈克尔乔丹", "雷吉米勒", "蒂姆邓肯", "科比布莱恩特" }));



            
            //2.用方法来实现：请计算出一个整型数组的平均值。{ 1, 3, 5, 7, 93, 33, 4, 4, 6, 8, 10 }。要求：计算结果如果有小数，则显示小数点后两位（四舍五入）。
            Console.WriteLine(Sums(new int[] { 1, 3, 5, 7, 93, 33, 4, 4, 6, 8, 10 }));

            //3.请通过冒泡排序法对整数数组{ 1, 3, 5, 7, 90, 2, 4, 6, 8, 10 }实现升序排序。
            int[] numbers = { 1, 3, 5, 7, 90, 2, 4, 6, 8, 10 };
            BubbleSort(numbers);

            Console.ReadLine();
        }

        public static string LongString(string[] vs)
        {
            string i = vs[0];
            for(int o =1;o<vs.Length; o++)
            {
                if (i.Length < vs[o].Length)
                {
                    i = vs[o];
                }
            }
            return i;
        }

        public static decimal Sums(int[] vs)
        {
            decimal i = 0;
            foreach(int o in vs)
            {
                i += o;
            }
            i =i / vs.Length;

            i = Math.Round(i , 2);

            return i;
        }

        public static void BubbleSort(int[] nums)
        {
            Console.WriteLine("排序前：");
            for (var i = 0; i < nums.Length; i++)
                Console.Write(nums[i] + " ");
            Console.WriteLine();
            Console.WriteLine("排序后：");

            for (var i = 0; i < nums.Length; i++)
            {
                for (var j = 0; j < nums.Length - 1 - i; j++)
                {
                    if (nums[j] > nums[j + 1])
                    {
                        int temp = nums[j];
                        nums[j] = nums[j + 1];
                        nums[j + 1] = temp;
                    }
                }
            }

            for (var i = 0; i < nums.Length; i++)
                Console.Write(nums[i] + " ");
            Console.WriteLine();
        }
    }
}
